﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Activities.Presentation.PropertyEditing;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using WFDataBaseProject.Controls;

namespace WFDataBaseProject.Helpers
{
    public class QueryEditor : DialogPropertyValueEditor
    {
        public QueryEditor()
        {
            this.InlineEditorTemplate = new DataTemplate();
            FrameworkElementFactory stack = new FrameworkElementFactory(typeof(StackPanel));
            stack.SetValue(StackPanel.OrientationProperty, Orientation.Horizontal);
            FrameworkElementFactory label = new FrameworkElementFactory(typeof(Label));
            Binding labelBinding = new Binding("StringValue");
            label.SetValue(Label.ContentProperty, labelBinding);
            label.SetValue(Label.MinWidthProperty, 90.0);
            stack.AppendChild(label);
            FrameworkElementFactory editModeSwitch = new FrameworkElementFactory(typeof(EditModeSwitchButton));
            editModeSwitch.SetValue(EditModeSwitchButton.TargetEditModeProperty, PropertyContainerEditMode.Dialog);
            stack.AppendChild(editModeSwitch);
            this.InlineEditorTemplate.VisualTree = stack;
        }

        public override void ShowDialog(PropertyValue propertyValue, IInputElement commandSource)
        {
            base.ShowDialog(propertyValue, commandSource);

            UCQueryEditor control = new UCQueryEditor();
            Window window = new Window();
            window.Title = "Query";
            window.ResizeMode = ResizeMode.NoResize;
            window.Content = control;
            window.SizeToContent = SizeToContent.WidthAndHeight;
            window.ShowInTaskbar = false;
            window.ShowActivated = true;
            window.ShowDialog();
            propertyValue.StringValue = control.Query;
        }
    }
}
